package leetco.test;

/**
 * 定义单向链表
 */
public class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    /**
     * 创建节点
     *
     * @param x ...
     * @return node
     */
    static ListNode createNode(int... x) {
        ListNode head = new ListNode(0);
        ListNode current = head;
        for (int i : x) {
            current.next = new ListNode(i);
            current = current.next;
        }
        return head.next;
    }

    @Override
    public String toString() {
        return val + " -> " + next;
    }
}
